<?php
/**
 * Created by PhpStorm.
 * User: songs
 * Date: 2019/11/6
 * Time: 20:31
 */

namespace App\Services\Api;
use App\admin\Service\OA;
use App\Jobs\Fun;
use App\Models\TokenUrlModel;
use App\Models\UploadPicModel;
use App\Services\Search\SearchService;
use Illuminate\Http\Request;

/// App\Services\Api\AppFun@
class AppFun extends ApiBase
{

    /**
     * 生成一个用于在授权在无cookie环境使用的md5代码
     */
    public function createMd5ToToken(Request $request){
        $Token=OA::$user->getToken();
        $url=$request->post('url','');
        if($url==''){
            OA::Json(1,'参数错误');
        }
        $md5=TokenUrlModel::createMd5ToToken($Token,$url);
        OA::Json(0,Fun::$HOST.'/h5/ToToken?md5='.$md5);
    }


    /**
     * 手机版搜索
     * 参数: word:表示关键词 type:gs,gc,gr 分别表示公司,工厂,个人
     */
    public function search_word(Request $request){
        $type=$request->post('type');
        $word=$request->post('word','');
        if($type!=='gs'&&$type!=='gc'&&$type!=='gr'&&$type!=='hd'&&$type!=='gw'){
            OA::Json(1,'参数错误');
        }
        if($word==''||strlen($word)>32){
            OA::Json(1,'关键词不符合要求');
        }
        $sear=new SearchService();
        $list=$sear->getFind($word,$type);
        OA::Json(0,$list);
    }



    /**
     * 	上传图片base64代码,并返回图片地址
     * 参数: post:图片的base64 返回图片的地址
     */
    public function upBasePic(Request $request){
        $upload=new UploadPicModel();
        $data = $upload->upPic($request->post('base64'));
        OA::Json(0,$data);
    }




}